package com.cristina.attention;

import com.cristina.attention.annotation.rest.AnonymousGetMapping;
import com.cristina.attention.utils.SpringContextHolder;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.bind.annotation.RestController;

/**
 * TODO @EnableFeignClients(basePackages = "com.cristina.attention.core.modules.support.feign")
 *
 * @Author superman
 * @Date 2021/11/25 22:40
 **/
@RestController
@EnableAsync
@Api(hidden = true)
@SpringBootApplication
@MapperScan(basePackages = {"com.cristina.attention.mapper"})
@EnableDiscoveryClient
@EnableTransactionManagement
@AllArgsConstructor
public class AttentionCoreApplication {

    public static void main(String[] args) {
        SpringApplication.run(AttentionCoreApplication.class, args);
    }

    @Bean
    public SpringContextHolder springContextHolder() {
        return new SpringContextHolder();
    }

    @Bean
    public ServletWebServerFactory webServerFactory() {
        TomcatServletWebServerFactory fa = new TomcatServletWebServerFactory();
        fa.addConnectorCustomizers(connector -> connector.setProperty("relaxedQueryChars", "[]{}"));
        return fa;
    }

    /**
     * 访问首页提示
     *
     * @return /
     */
    @AnonymousGetMapping("/")
    public String index() {
        return "Backend service started successfully";
    }
}
